<?php
namespace clt;
use clt\Curl;
class Ucenter {
	public $domain='http://demo.cloudfast.com/ucenter';
	public $key = 'U-e06ab-06acd-545ff-b591c';
	public function getHeader(){
		$timestamp = time();
		return $header = array("X-Auth-Token:".md5($this->key.time())."|".time());
	}
	/*判断是否可以登录*/
	public function checkLogin($email,$password){
		$curl = new Curl;
        $result = $curl->_post($this->domain.'/member/checkLogin',['email'=>$email,'password'=>$password],false,$this->getHeader());
        $result = json_decode($result,true);
        if(isset($result['code']) && $result['code'] == 0){
        	return $result['data'];
        }	
        return false;
	}
	/*修改密码*/
	public function editPassword($email,$password){
		$curl = new Curl;
        $result = $curl->_post($this->domain.'/member/editPassword',['email'=>$email,'password'=>$password],false,$this->getHeader());
        $result = json_decode($result,true);
        if(isset($result['code']) && $result['code'] == 0){
        	return true;
        }	
        return $result['msg'];
	}
	/*删除用户*/
	public function delUser($uid){
		
	}
	/*修改密码*/
	public function editUser($data){
		$curl = new Curl;
        $result = $curl->_post($this->domain.'/member/editUser',$data,false,$this->getHeader());
        $result = json_decode($result,true);
        if(isset($result['code']) && $result['code'] == 0){
        	return true;
        }	
        return $result['msg'];
	}
	/*获取用户uid*/
	public function getUid($email){
		$curl = new Curl;
        $result = $curl->_get($this->domain.'/member/getUid?email='.$email,$this->getHeader());
        $result = json_decode($result,true);
        if(isset($result['code']) && $result['code'] == 0){
        	return $result['uid'];
        }	
        return 0;
	}
	/*获取用户信息*/
	public function getUser($parameter){
		$curl = new Curl;
		$result = $curl->_get($this->domain.'/member/getUser?parameter='.$parameter,$this->getHeader());
		$result = json_decode($result,true);
	   	if(isset($result['code']) && $result['code'] == 0){
        	return $result['data'];
        }	
        return false;
	}
	/*用户注册*/
	public function register($data){
		$curl = new Curl;
		$result = $curl->_post($this->domain.'/member/register',$data,false,$this->getHeader());
		$result = json_decode($result,true);
	   	if(isset($result['code']) && $result['code'] == 0){
        	return true;
        }	
        return $result['error'];
	}
	/*用户注册*/
	public function syncUser($data){
		$curl = new Curl;
		$result = $curl->_post($this->domain.'/member/syncUser',$data,false,$this->getHeader());
		$result = json_decode($result,true);
	   	if(isset($result['code']) && $result['code'] == 0){
        	return true;
        }	
        return $result['error'];
	}
	/*用户删除*/
	public function delete($email){
		if(!empty($email)){
			$curl = new Curl;
			$result = $curl->_get($this->domain.'/member/delete?email='.$email,$this->getHeader());
			$result = json_decode($result,true);
			if(isset($result['code']) && $result['code'] == 0){
				return true;
			}
		}
		return false;
	}
}